import { getAreaConfig, getIndustryConfig, getTagTypeConfig } from '@/utils/filterConfig';
import {
  getBondType,
  getCaliberType,
  getFinancialType,
  getCompanyType,
  getGreenProjectClass,
  getVarietyType, getGreenProjectCategory
} from './../apis';
import { ComponentType } from 'vc';
import { useRequest } from 'vue-request';

export function useScreen() {
  const PAGE_SIZE = 15;

  const queryData = reactive<any>({
    pageNum: 1,
    pageSize: PAGE_SIZE,
    searchTxt: '',
    sortRule: '',
    provinceCode: '',
    cityCode: '',
    countryCode: ''
    // sort: 'desc',
  });

  const option1 = [
    { name: '不限', code: '' },
    { name: '是', code: 2 },
    { name: '否', code: 1 }
  ];
  const option2 = [
    { name: '不限', code: '' },
    { name: '有', code: 1 },
    { name: '无', code: 2 }
  ];

  const moreData = [
    {
      name: '是否有第三方评估认证',
      code: 'hasFacilityRating',
      data: option2
    },
    {
      name: '是否到期',
      code: 'maturityType',
      data: option1
    }
  ];


  // 地区
  const areaData = getAreaConfig();
  areaData.value.submitFn = (val) => {
    const { lv1, lv2, lv3 } = val;

    queryData.provinceCode = lv1.join();
    queryData.cityCode = lv2.join();
    queryData.countryCode = lv3.join();
  };

  // 项目类别
  const { data: caliberData } = useRequest(getGreenProjectClass, {});
  const caliberTypeData = {
    title: '项目类别',
    component: ComponentType.CASCADER,
    options: caliberData,
    required: false,
    submitFn: (data) => {
      const { lv1, lv2, lv3 } = data;
      queryData.classificationLevel1 = lv1.join();
      queryData.classificationLevel2 = lv2.join();
      queryData.classificationLevel3 = lv3.join();
    }
  };

  // 项目主体
  const { data: varietyData } = useRequest(getCompanyType, {});
  const varietyTypeData = {
    title: '项目主体',
    component: ComponentType.MULTIPLE,
    options: varietyData,
    required: false,
    submitFn: (data) => {
      queryData.companyType = data;
    }
  };


  // 项目归属类别
  const { data } = useRequest(getGreenProjectCategory, {});
  const classTypeData = {
    title: '项目归属类别',
    component: ComponentType.MULTIPLE,
    options: data,
    submitFn: (data) => {
      queryData.projectCategory = data;
    }
  };


  // 更多
  const moreFilter = ref({
    title: '项目总投资金额',
    component: ComponentType.SINGLE,
    customType: 'range',
    customUnit: '亿',
    options: [
      { name: '0-5亿', code: '0,5' },
      { name: '5-10亿', code: '5,10' },
      { name: '10-50亿', code: '10,50' },
      { name: '50-100亿', code: '50,100' },
      { name: '100亿以上', code: '100,' }
    ],
    required: false,
    submitFn: (val: string) => {
      queryData.totalInvestmentStart = val ? val.split(',')[0] : '';
      queryData.totalInvestmentEnd = val ? val.split(',')[1] : '';
    }
  });

  // 项目建设起始年份
  const dateData = {
    title: '项目建设起始年份',
    component: ComponentType.DATE,
    type: 'daterange',
    submitFn: (data) => {
      queryData.startingYearStart = data[0] ? data[0].split('-')[0] : '';
      queryData.startingYearEnd = data[1] ? data[1].split('-')[0] : '';
    }
  };

  const screen = ref([areaData.value, caliberTypeData, varietyTypeData, classTypeData, moreFilter.value, dateData
  ]);

  return {
    PAGE_SIZE,
    screen,
    queryData
  };
}
